/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.address;

import junit.framework.TestCase;

import javax.sip.address.Address;
import javax.sip.address.SipURI;
import java.text.ParseException;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class AddressParserTest extends TestCase {
    public AddressParserTest(String name) {
        super(name);
    }

    public void testParsing() {
        final String DISPLAY_NAME = "Dmitriy Parkhonin";
        byte[] bytes = (DISPLAY_NAME + " <sip:deps@jnetx.ru>").getBytes();
        Address address = null;
        try {
            address = AddressParser.parse(null, bytes, 0, bytes.length);
        } catch (ParseException e) {
            fail("Cannot parse the address!");
        }
        assertEquals("Display name is wrong!", DISPLAY_NAME, address.getDisplayName());
        final SipURI uri = SipURIImpl.createLazily("sip:deps@jnetx.ru");
        assertEquals("URI is wrong!", uri, address.getURI());
        assertEquals("The string representation is wrong!", "\""+DISPLAY_NAME+"\" <sip:deps@jnetx.ru>", address.toString());
    }

    public void testNoDisplayName() {
        byte[] bytes = "<sip:deps@jnetx.ru>".getBytes();
        Address address = null;
        try {
            address = AddressParser.parse(null, bytes, 0, bytes.length);
        } catch (ParseException e) {
            fail("Cannot parse the address!");
        }
        assertNull("Display name is not null!", address.getDisplayName());
        final SipURI uri = SipURIImpl.createLazily("sip:deps@jnetx.ru");
        assertEquals("URI is wrong!", uri, address.getURI());
        assertEquals("The string representation is wrong!", "<sip:deps@jnetx.ru>", address.toString());
    }
}
/*
 * $Log$
 */